<?php

    class Admin_ProvidersController extends Zend_Controller_Action {

        public function init() {
            /* Initialize action controller here */
        }

        public function indexAction() {
            // action body
            $provider = new Admin_Model_ProviderMapper();
            $arr = $provider->_getAll();
            $this->view->assign('providers', $arr);
        }

        public function addAction() {
            $this->_helper->layout()->disableLayout();
            $table = new Application_Model_DbTable_Provider();
            $provider = new Admin_Model_ProviderMapper();

            if (isset($_POST['submit'])) {
                $this->_helper->viewRenderer->setNoRender(true);
                $name = $_POST['txtUsername'];
                $provider->_insert($name);
                echo 'OK';
            }
        }

        public function deleteAction() {
            // action body
            $arr = $_GET['chkCustomer'];
            $provider = new Admin_Model_ProviderMapper();
            foreach ($arr as $id) {
                $provider->_delete($id);
            }
            header("location: /aitishop/admin/providers");
        }

        public function updateAction() {
            // action body
            $this->_helper->layout()->disableLayout();
            $provider = new Admin_Model_ProviderMapper();
            if (isset($_POST['submit'])) {
                $this->_helper->viewRenderer->setNoRender(true);
                $id = $_POST['txtId'];
                $name = $_POST['txtUsername'];
                $provider->_update($id, $name);
                echo 'OK';
            } else {
                $id = $_GET['id'];
                $result = $provider->_getById($id);
                $this->view->assign('provider', $result);
            }
        }

    }
